function showDialog()
{
	var caja= $('<div style="font-size:small" title="About"><p>Proyecto realizado por:</p><p>- Masserini Mauro</p><p>- Zapata Lucia</p></div>');
   	caja.dialog();
}

$(window).load(function(){    
    $(window).resize(function() {
        resize_photogrid();
	resize_photogrid();
    });

    makeAJAXCall();
});

function resize_photogrid(){
    win_width = $(window).width();
    
    win_height = $(window).height();
    $('#photogrid_wrapper').css('height',win_height);
    
    doc_height = $(document).height();
    
    final_height = (win_height > doc_height) ? win_height : doc_height;
    
    $('#photogrid_wrapper').css('width',win_width);
    $('#photogrid_wrapper').css('height',final_height);
    
    $('#photogrid').css('width',win_width + 400);
    $('#photogrid').css('height',final_height + 400);
}

function apply_masonry(appeded){
    if(!transition_masonry){
	resize_photogrid();
    }
    
    transition_masonry = true;
    $('#photogrid').masonry({ columnWidth: 160, itemSelector: 'div', isAnimated: true,animationOptions: {
    duration: 750,
    easing: 'linear',
    queue: false
  }});
    
    $('#photogrid div').each(function(i, val) {
	    var r = Math.random()*5;
	    $('a img',this).fadeTo(0,opacity_off);
	    $('a',this).delay(r*500).css('visibility','visible').hide().fadeTo(400,1);
	    $(this).hover(function() {
		$('a img',this).stop(true, true).fadeTo(400,opacity_on);
	    },function() {
		$('a img',this).stop(true, true).fadeTo(600,opacity_off);
	    });
	});
	
	//Menu
	$('#menu_wrapper').delay(2600).show('clip','slow');
	var color = Math.floor((Math.random()*360));
	$('#menu').css('border-color','hsl('+color+', 84%, 50%)');
}



var opacity_off = .3;
var opacity_on = 1;
var menu_visible = false;
var transition_masonry = false;

function makeAJAXCall(){
    $.ajax({
	url: "img_server.php",
	success: function(data, textStatus, jqXHR){
	    total_photos_loaded = 0;
	    $('#photogrid').removeClass('masoned').html(data);
	    $('#photogrid img').load(image_loaded);
	}
    });
}

var total_photos_loaded = 0;

function image_loaded(){
    total_photos_loaded = total_photos_loaded + 1;
    if(total_photos_loaded == 10){
	$('#photogrid img').unbind('load');
	apply_masonry();
    }
}